<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html><head>


   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <meta name="GENERATOR" content="Mozilla/4.73 [en] (Win98; U) [Netscape]">
   <title>Reverse and Add</title>
<!--Converted with LaTeX2HTML 96.1 (Feb 5, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->
</head><body lang="EN" bgcolor="#ffffff">

<h1>
</h1>

<center><table bgcolor="#0060f0">
<tbody><tr>
<td><a name="SECTION0001000000000000000000"></a><b><font color="#c0ffff"><font size="+2">Reverse
and Add</font></font></b></td>
</tr>
</tbody></table></center>

<h2>
<a name="SECTION0001002000000000000000"></a><font color="#0070e8">The Problem</font></h2>
The "reverse and add" method is simple: choose a number, reverse its digits
and add it to the original. If the sum is not a palindrome (which means,
it is not the same number from left to right and right to left), repeat
this procedure.
<p>For example:
<br>195 Initial number
<br>591
<br>-----
<br>786
<br>687
<br>-----
<br>1473
<br>3741
<br>-----
<br>5214
<br>4125
<br>-----
<br>9339 Resulting palindrome
</p><p>In this particular case the palindrome 9339 appeared after the 4th addition.
This method leads to palindromes in a few step for almost all of the integers.
But there are interesting exceptions. 196 is the first number for which
no palindrome has been found. It is not proven though, that there is no
such a palindrome.
</p><p>Task :
<br>You must write a program that give the resulting palindrome and the
number of iterations (additions) to compute the palindrome.
</p><p>You might assume that all tests data on this problem:
<br>- will have an answer ,
<br>- will be computable with less than 1000 iterations (additions),
<br>- will yield a palindrome that is not greater than 4,294,967,295.
<br>&nbsp;
</p><h2>
<a name="SECTION0001003000000000000000"></a><font color="#0070e8">The Input</font></h2>
The first line will have a number N with the number of
test cases, the next N lines will have a number P to compute its palindrome.
<h2>
<a name="SECTION0001004000000000000000"></a><font color="#0070e8">The Output</font></h2>
For each of the N tests you will have to write a line with the following
data : minimum number of iterations (additions) to get to the palindrome
and the resulting palindrome itself separated by one space.
<h2>
<a name="SECTION0001005000000000000000"></a><font color="#0070e8">Sample
Input</font></h2>

<pre>3
195
265
750
</pre>

<h2>
<a name="SECTION0001006000000000000000"></a><font color="#0070e8">Sample
Output</font></h2>
4 9339
<br>5 45254
<br>3 6666
</body></html>